package es.udc.fic.hamNeggs.dao;

import es.udc.fic.hamNeggs.manager.UserStoriesManager;
import es.udc.fic.hamNeggs.pojo.UserStoriesCategory;

import java.util.ArrayList;

public class InputCategory {
    private String            id;

    private String            category;

    private ArrayList<String> userStories;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public ArrayList<String> getUserStories() {
        return userStories;
    }

    public void setUserStories(ArrayList<String> userStories) {
        this.userStories = userStories;
    }

    public UserStoriesCategory toCategory() {
        UserStoriesCategory ctg = new UserStoriesCategory();
        UserStoriesManager ustmng = new UserStoriesManager();

        if (id != null && id != "")
            ctg.setId(new Long(id));

        if (category != null && category != "")
            ctg.setCategory(category);

        if (userStories != null)
            for (String ust : userStories)
                ctg.setOneUserStories(ustmng.getUserStories(new Long(ust)));

        ustmng.close();
        return ctg;
    }

    public void setCategory(UserStoriesCategory ctg) {
        if (ctg.getId() != null)
            id = ctg.getId().toString();
        if (ctg.getCategory() != null)
            category = ctg.getCategory();
        // if (ctg.getUserStories() != null)
        // for (UserStories ust : ctg.getUserStories())
        // userStories.add(ust.getId().toString());

    }

}
